SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE dbo.[DnnProduct_CDS_CategoriesCountByName]
	@DistributorID varchar(50),
	@ParentID int = null,
	@Name nvarchar(50)
AS
BEGIN
	IF (@ParentID IS NULL OR @ParentID <= 0)
	BEGIN
		SELECT count([ID])
		FROM DnnProduct_CDS_Categories
		WHERE DistributorID = @DistributorID AND ParentID IS NULL AND [Name] = @Name
	END
	ELSE
	BEGIN
		SELECT count([ID])
		FROM DnnProduct_CDS_Categories
		WHERE DistributorID = @DistributorID AND ParentID = @ParentID AND [Name] = @Name
	END
END
GO
